package com.example.studyPlatform.controller;

import com.example.studyPlatform.config.ThemeConfig;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.ServletContext;

import static com.example.studyPlatform.config.RoutingConstant.API_PATH;
import static com.example.studyPlatform.config.RoutingConstant.PUBLIC_PATH;

@Controller
@AllArgsConstructor
public class ArchiveController {
    ServletContext context;
    ThemeConfig themeConfig;

    @GetMapping("/search")
    public String searchPage(String keyword, Model model) {
        String path = context.getContextPath();
        if(!path.equals(""))path+="/";
        path += API_PATH + "/search";
        model.addAttribute("url", path + "?keyword=" + keyword);
        return themeConfig.render(PUBLIC_PATH + "/archive");
    }

}
